import time
from multiprocessing.pool import ThreadPool
from multiprocessing import Lock

import requests
from loguru import logger
import redis
headers = {
    "88ba31b147627d352bb7": "f5de247589a732b7266a09170f83a4b5d524c11449d4f5b29194a78e34990d7cecb64609a0fcbf31467f5d0de693608101b4d8332119408fc0d0b50ea795b74f",
    "accept": "application/json, text/plain, */*",
    "accept-language": "zh-CN,zh;q=0.9,en;q=0.8",
    "cache-control": "no-cache",
    "pragma": "no-cache",
    "priority": "u=1, i",
    "referer": "https://www.qcc.com/web/search?key=%E5%B0%8F%E7%B1%B3%E7%A7%91%E6%8A%80%E6%9C%89%E9%99%90%E8%B4%A3%E4%BB%BB%E5%85%AC%E5%8F%B8",
    "sec-ch-ua": "\"Microsoft Edge\";v=\"129\", \"Not=A?Brand\";v=\"8\", \"Chromium\";v=\"129\"",
    "sec-ch-ua-mobile": "?0",
    "sec-ch-ua-platform": "\"Windows\"",
    "sec-fetch-dest": "empty",
    "sec-fetch-mode": "cors",
    "sec-fetch-site": "same-origin",
    "user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/129.0.0.0 Safari/537.36 Edg/129.0.0.0",
    "x-pid": "285e5c97574270306b5b0713a0f600da",
    "x-requested-with": "XMLHttpRequest"
}

url = "https://www.qcc.com/api/search/searchMind"
params = {
    "mindKeyWords": "true",
    "mindType": "9",
    "pageSize": "5",
    "person": "true",
    "searchKey": "小米科技有限责任公司",
    "suggest": "true"
}
cookies = {
    "qcc_did": "9782aea1-e515-4580-8426-0387be81e79e",
    "QCCSESSID": "e619f20bff4ca90347d5e667ba",
    "acw_tc": "1a0c384d17272652468587103e00e9da5c36fac19eb7f2b0afc597af6cbf25",
}


def a(lock):
    lock.acquire()
    time.sleep(3)
    lock.release()
    response = requests.get(url, headers=headers, cookies=cookies, params=params)
    if response.text.startswith('{"list":[{"KeyNo":"9cce0780ab7644008b73bc21'):
        logger.success("1")
    else:
        print(response.text)
        logger.error("---------------------------------")

if __name__ == '__main__':
    r = redis.Redis(host='localhost', port=6379, password='python', decode_responses=True)
    pool=ThreadPool(100)
    lock=Lock()
    for i in range(1000):
        pool.apply_async(a,(lock,))
    pool.close()
    pool.join()
    print("结束了")



